package top.lc951.myandroid;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import top.lc951.myandroid.views.card4.CardLayoutManager;
import top.lc951.myandroid.views.card4.ItemTouchHelperCallback;
import top.lc951.myandroid.views.card5.CardLayoutManagerLan;
import top.lc951.myandroid.views.card5.CardViewHelperCallback;

public class CardOverlayRecyclerViewActivity2 extends AppCompatActivity {
    RecyclerView rv;
    List<Bean> mStrings = new ArrayList<>();
    public static void actionActivity(Context context) {
        Intent intent = new Intent(context, CardOverlayRecyclerViewActivity2.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_card_overlay_recycler_view2);

        rv =  findViewById(R.id.rv);
        rv.setLayoutManager(new CardLayoutManagerLan(rv));

        for (int i = 1; i < 4; i++) {
            mStrings.add(0,new Bean(i,String.valueOf(i)));
        }

        MyAdapter myAdapter = new MyAdapter(this, mStrings);
        rv.setAdapter(myAdapter);

        CardViewHelperCallback itemTouchHelperCallback = new CardViewHelperCallback(mStrings, myAdapter);
        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback);
        itemTouchHelper.attachToRecyclerView(rv);
    }

    public class Bean{
        public Bean(int index,String value) {
            this.value = value;
            this.index=index;
        }

        int index;

        String value;
        int direction=ItemTouchHelper.RIGHT;

        public int getIndex() {
            return index;
        }

        public void setIndex(int index) {
            this.index = index;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getDirection() {
            return direction;
        }

        public void setDirection(int direction) {
            this.direction = direction;
        }

        @Override
        public String toString() {
            return "Bean{" +
                    "index=" + index +
                    ", value='" + value + '\'' +
                    ", direction=" + direction +
                    '}';
        }
    }

    class MyAdapter extends RecyclerView.Adapter {
        private Context mContext;
        private List<Bean> mStrings;

        public MyAdapter(Context mContext, List<Bean> mStrings) {
            this.mContext = mContext;
            this.mStrings = mStrings;
        }

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
            return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_recyclerview, viewGroup, false));
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
            MyViewHolder myViewHolder = (MyViewHolder) viewHolder;

            myViewHolder.textView.setText(mStrings.get(i).getValue() + "/" + getItemCount());
            viewHolder.itemView.setTag(mStrings.get(i));
        }

        @Override
        public int getItemCount() {
            return mStrings.size();
        }

        class MyViewHolder extends RecyclerView.ViewHolder {
            public TextView textView;

            public MyViewHolder(@NonNull View itemView) {
                super(itemView);
                textView = itemView.findViewById(R.id.tv);
            }
        }
    }
}